﻿// ***************************轮播图************************************

var pos = 0;
var aImgBox = document.getElementById('img_box').getElementsByTagName('img');
var aLi = document.getElementById('circle').getElementsByTagName('li');
var oHdBanner = document.getElementById('banner');
// 安装定时器
var timer = setInterval(function(){
	carousel(1);
},3000);

oHdBanner.onmouseover = function(){
	clearInterval(timer);
}
oHdBanner.onmouseout = function(){
	timer = setInterval(function(){
		carousel(1);
	},3000);
}

function carousel(num){
	pos+=num;
	if(pos==aImgBox.length){
		pos = 0;
	}else if(pos<0){
		pos=aImgBox.length-1;
	}
	for(var i=0;i<aImgBox.length;i++){
		aImgBox[i].style.display = 'none';
		aLi[i].style.backgroundColor = '#fff'
	}
	aImgBox[pos].style.display = 'block';
	aLi[pos].style.backgroundColor = '#c94224'
}
// 圆点轮播
for(var j=0;j<aLi.length;j++){
	aLi[j].index = j;
	aLi[j].onmouseover = function(){
		for(var i=0;i<aImgBox.length;i++){
			aImgBox[i].style.display = 'none';
			aLi[i].style.backgroundColor = '#fff';
		}
		aImgBox[this.index].style.display = 'block';
		this.style.backgroundColor = '#c94224';
		pos = this.index;
	}
}
function OpenSrc(thisid) {
    switch (thisid) {
        case "sh0":
            $('#hqimg').attr("src", "https://image.sinajs.cn/newchart/min/n/sh000001.gif?t=" + (new Date).getTime());
            break;
        case "sh1":
            $('#hqimg').attr("src", "https://image.sinajs.cn/newchart/daily/n/sh000001.gif?t=" + (new Date).getTime());
            break;
        case "sh2":
            $('#hqimg').attr("src", "https://image.sinajs.cn/newchart/weekly/n/sh000001.gif?t=" + (new Date).getTime());
            break;
        case "sh3":
            $('#hqimg').attr("src", "https://image.sinajs.cn/newchart/monthly/n/sh000001.gif?t=" + (new Date).getTime());
            break;
        case "sz0":
            $('#hqimg').attr("src", "https://image.sinajs.cn/newchart/min/n/sz399001.gif?t=" + (new Date).getTime());
            break;
        case "sz1":
            $('#hqimg').attr("src", "https://image.sinajs.cn/newchart/daily/n/sz399001.gif?t=" + (new Date).getTime());
            break;
        case "sz2":
            $('#hqimg').attr("src", "https://image.sinajs.cn/newchart/weekly/n/sz399001.gif?t=" + (new Date).getTime());
            break;
        case "sz3":
            $('#hqimg').attr("src", "https://image.sinajs.cn/newchart/monthly/n/sz399001.gif?t=" + (new Date).getTime());
            break;
    }
}
// ***************************选项卡************************************
var thisitem = "sh";
$(".quotes_menu div").click(function () {
    thisitem = $(this).attr("data-item");
    $(".quotes_menu .current").each(function () {
        $(this).removeClass("current");
    });
    $(this).addClass("current");
    OpenSrc(thisitem+"0");
});
$('.hq_txt a').click(function () {
    //$('#hq_img').show();
    var thisitemid = $(this).attr("data-item");
    $(".hq_txt .act").each(function () {
        $(this).removeClass("act");
        $(this).addClass("cur");
    });
    $(this).addClass("act");
    OpenSrc(thisitem + thisitemid);
})